/*Keeps and maintains the heightmap data for the simulation*/
import java.util.Random;

public class HeightMap
{
 static int[][] map;// the internal representation of the heightmap
 public static int SIZE;// This size of the map

 public static int getHeightHere(loc L)
 {
   return map[L.x][L.y];
 } 
 
 public static void Intialize()
 {
  //generate an inital height map 
  SIZE=SimulationConstants.simsize;
  Random R = new Random();
  map = new int[SIZE+1][SIZE+1];
  map[0][0]=R.nextInt(255);
  map[0][SIZE]=R.nextInt(255);
  map[SIZE][SIZE]=R.nextInt(255);
  map[SIZE][0]=R.nextInt(255);
  domap(0,0,SIZE);
  HumidMap.initalize();
 }
 
  public static void domap(int x, int y, int size)
 {
  int xmid = x + size/2;//halfway point
  int xmax = x + size;//max point
  int ymid = y + size/2;
  int ymax = y + size;
  Random R = new Random();
  map[xmid][y]= ((map[x][y]+map[xmax][y])/2)+R.nextInt(20)-10;//bottom horizontal midpoint
  map[xmid][ymax]= ((map[x][ymax]+map[xmax][ymax])/2)+R.nextInt(20)-10;//top horizontal midpoint
  map[x][ymid]= ((map[x][y]+map[x][ymax])/2)+R.nextInt(20)-10;//left vertical midpoint
  map[xmax][ymid]= ((map[xmax][y]+map[xmax][ymax])/2+R.nextInt(20)-10);//right vertical midpoint
  map[xmid][ymid]=(map[x][y]+map[x][ymax]+map[xmax][y]+map[xmax][ymax])/4+R.nextInt(20)-10;


  if(size>1)
   {
   domap(x,y,size/2);
   domap(xmid,y,size/2);
   domap(x,ymid,size/2);
   domap(xmid,ymid,size/2);
   }
 }
 public static int[][] GetHeightMap()
 {
  //returns raw data for renderer
   return map;
 }
 public static void SetMapData(int[][] savedmap) {
   map = savedmap;
   
 }
  
}